use bitvec::prelude::*;
use colored::Colorize;

type BitSeq = BitArr!(for VAR_NUM, in u8, Msb0);

const VAR_NUM: usize = 128;

#[derive(Clone)]
pub struct DisVec {
  pub dex: BitSeq,
  pub pol: BitSeq,
}

impl DisVec {
  pub fn new() -> Self {
    DisVec {
      dex: bitarr!(u8, Msb0; 0; VAR_NUM),
      pol: bitarr!(u8, Msb0; 0; VAR_NUM),
    }
  }

  // pub fn rst(&mut self) {
  //   self.dex.fill(false);
  //   self.pol.fill(false);
  // }

  pub fn set(&mut self, l: i32) {
    assert!(l != 0);
    let dex = l.abs() as usize;
    self.dex.set(dex, true);
    self.pol.set(dex, l > 0);
  }

  // pub fn clr(&mut self, l: i32) {
  //   let dex = l.abs() as usize;
  //   self.dex.set(dex, false);
  //   self.pol.set(dex, false);
  // }

  pub fn any(&self, oppo: &DisVec) -> bool {
    (self.dex & oppo.dex & !(self.pol ^ oppo.pol)).any()
  }

  // pub fn print(&self, len: usize) {
  //   for i in 1..len {
  //     if *self.dex.get(i).unwrap() {
  //       print!("+".color("green").on_truecolor(32, 32, 32));
  //     } else if *self.pol.get(i).unwrap() {
  //       print!("+".color("green").on_truecolor(32, 32, 32));
  //     } else {
  //       print!("+".color("red").on_truecolor(32, 32, 32));
  //     }
  //   }
  // }
}
